library(SDMTools)

wd="/home/jc214262/Refugia/Vertebrate_data/";setwd(wd)

species.data=read.csv('/home/jc214262/Refugia/species_points/all.vert.records_sorted_list_to_use2.csv',as.is=TRUE)
ibra.spp=species.data$Species[which(species.data$action1=='central_aus_mask' | species.data$action1=='intrastate'  | species.data$action1=='SW_mask')]
state.spp=species.data$Species[which(species.data$action1=='state_mask')]

ibra=read.csv('/home/jc148322/AP02/ibras/ibras.presence.csv')
state=read.csv('/home/jc148322/AP02/states/states.presence.csv')

ibra.sub=ibra[which(ibra$species %in% ibra.spp),]
state.sub=state[which(state$species %in% state.spp),]

write.csv(ibra.sub, '/home/jc148322/AP02/ibras/ibra.sub.csv',row.names=FALSE)
write.csv(state.sub, '/home/jc148322/AP02/states/state.sub.csv',row.names=FALSE)


files=list.files('/home/jc148322/AP02/states/',pattern='.png')
files=files[1:197]
files=gsub('.png','',files)
unwanted=setdiff(files,state.spp)
unwanted=paste(unwanted,'.png',sep='')
setwd('/home/jc148322/AP02/states/')
unlink(unwanted)


files=list.files('/home/jc148322/AP02/ibras/',pattern='.png')
files=gsub('.png','',files)
unwanted=setdiff(files,ibra.spp)
unwanted=paste(unwanted,'.png',sep='')
setwd('/home/jc148322/AP02/ibras/')
unlink(unwanted)









